<template>
    <van-nav-bar title="详情" left-text="返回" left-arrow @click-left="() => { $router.back('/sousuo') }" fixed />
   <van-swipe :autoplay="3000" lazy-render>
  <van-swipe-item v-for="image in images" :key="image">
    <img :src="image" />
  </van-swipe-item>
</van-swipe>
<!-- 富文本 -->
 <div v-html="xiangqingData.goods_introduce"></div>
      
      <!-- 动作栏 -->
       <van-action-bar>
  <van-action-bar-icon icon="chat-o" text="客服" color="#ee0a24" />
  <van-action-bar-icon icon="cart-o" text="购物车" />
  <van-action-bar-icon icon="star" text="已收藏" color="#ff5000" />
  <van-action-bar-button type="warning" text="加入购物车" @click="cart" />
  <van-action-bar-button type="danger" text="立即购买" />
</van-action-bar>

</template>

<script setup>
import { ref } from 'vue';
const images=ref([])
const xiangqingData=ref({})
import { useRoute,useRouter} from 'vue-router';
 let route=new useRoute
 let router=new useRouter
  import {xiangqingApi} from'@/api/api'
xiangqingApi(route.params.goods_id).then(res=>{
    console.log('详情',res)
     xiangqingData.value=res.data.message
     for(let i=0;i<res.data.message.pics;i++)
     {
        images.value.push(res.data.message.pics[i].pics_mid)
     }

})

import { useCounterStore } from '@/stores/counter'
// 可以在组件中的任意位置访问 `store` 变量 ✨
const store = useCounterStore()
import { showToast } from 'vant';
const cart=()=>{
   let token=localStorage.getItem('token')
     if(!token)
     {
         showToast({
            message: '请先登录',
           type:'success',
            onClose(){
                router.push('/login')
            }
        });
     }
     else
     {
          store.jr(xiangqingData.value,route.params.goods_id)
              router.push('/home/cart')
     }
}
</script>

<style lang="scss" scoped>

</style>